package com.ssyan.boot.controller;

import com.ssyan.boot.entity.User;
import com.ssyan.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @author ssyan
 * @Description 控制层
 * @create 2021/8/17 17:09
 * @Version 1.0
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    // localhost:8081/user/xxx
    @GetMapping("/user/{id}")
    public Mono<User> getUserById(@PathVariable Integer id) {
        return userService.getUserById(id);
    }

    //localhost:8081/user
    @GetMapping("/user")
    public Flux<User> getAllUser() {
        return userService.getAllUser();
    }

    @PostMapping("/saveuser")
    public Mono<Void> addUser(@RequestBody User user) {
        Mono<User> userMono = Mono.just(user);
        return userService.addUser(userMono);
    }
}
